package com.zking.controller;

import com.zking.entity.User;
import com.zking.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller @RequiredArgsConstructor
public class MyController1 {
    private final UserService userService;
    
    @RequestMapping({"/", "/index"})
    public String index(Model model) {
        model.addAttribute("user", new User(1, "老刘", "123", .12));
        model.addAttribute("thread", Thread.currentThread().getName());
        
        userService.findAll(); // 阻塞
        System.out.println("-----------------");
        userService.findAllAsync(); // 不会阻塞
        return "index";
    }
    
    @RequestMapping("/t1")
    public String test1(Model model, HttpSession session) {
        session.setAttribute("login", "老王");
        session.setAttribute("money", 5);
        session.setAttribute("color", "green");
        // session.invalidate();
        return "test";
    }
    
    @RequestMapping("/t2")
    public String test2(Model model, HttpSession session) {
        return "page";
    }
}
